/**
 * Copyright (C) 2018-2019
 * All rights reserved, Designed By www.joolun.com
 */
package com.joolun.web.controller.mall;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.joolun.common.core.controller.BaseController;
import com.joolun.common.core.domain.AjaxResult;
import com.joolun.mall.entity.Apply;
import com.joolun.mall.service.ApplyService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.AllArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import java.time.LocalDateTime;

/**
 * 志愿报名
 */
@Slf4j
@RestController
@AllArgsConstructor
@RequestMapping("/apply")
@Api(value = "Apply", tags = "志愿报名管理")
public class ApplyController extends BaseController {

    private final ApplyService baseService;

    /**
    * 分页查询
    * @param page 分页对象
    * @param entity 志愿报名
    * @return
    */
	@ApiOperation(value = "分页查询")
    @GetMapping("/page")
    @PreAuthorize("@ss.hasPermi('mall:apply:index')")
    public AjaxResult getApplyPage(Page page, Apply entity) {
        return AjaxResult.success(baseService.page1(page,entity));
    }

    /**
    * 通过id查询志愿报名
    * @param id
    * @return R
    */
	@ApiOperation(value = "通过id查询志愿报名")
    @GetMapping("/{id}")
    @PreAuthorize("@ss.hasPermi('mall:apply:get')")
    public AjaxResult getById(@PathVariable("id") String id){
        return AjaxResult.success(baseService.getById(id));
    }

    /**
    * 新增志愿报名
    * @param entity 志愿报名
    * @return R
    */
	@ApiOperation(value = "新增志愿报名")
    @PostMapping
    @PreAuthorize("@ss.hasPermi('mall:apply:add')")
    public AjaxResult save(@RequestBody Apply entity){
        entity.setCreateTime(LocalDateTime.now());
        return AjaxResult.success(baseService.save(entity));
    }

    /**
    * 修改志愿报名
    * @param entity 志愿报名
    * @return R
    */
	@ApiOperation(value = "修改志愿报名")
    @PutMapping
    @PreAuthorize("@ss.hasPermi('mall:apply:edit')")
    public AjaxResult updateById(@RequestBody Apply entity){
        return AjaxResult.success(baseService.updateById(entity));
    }

    /**
    * 通过id删除志愿报名
    * @param id
    * @return R
    */
	@ApiOperation(value = "通过id删除志愿报名")
    @DeleteMapping("/{id}")
    @PreAuthorize("@ss.hasPermi('mall:apply:del')")
    public AjaxResult removeById(@PathVariable String id){
        return AjaxResult.success(baseService.removeById(id));
    }

}
